package cn.k23.config.autoconfig;

import cn.k23.config.TokenInterceptorRegistry;
import cn.k23.interceptor.TokenInterceptor;
import cn.k23.utils.TokenUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @Author: k23
 * @Date: 2022-05-10 9:45
 * @Version: 1.0
 */
@Configuration(
        proxyBeanMethods = false
)

//批量属性注解
@EnableConfigurationProperties(TokenProperties.class)

@ConditionalOnProperty(
        prefix = "by.token",
        value = "enabled",
        havingValue = "true",
        matchIfMissing = true
)
public class TokenAutoConfiguration {

    TokenProperties properties;

    //构造注入属性
    public TokenAutoConfiguration(TokenProperties tokenProperties){
        this.properties = tokenProperties;
    }

    //向ioc容器注入 拦截器注册类的实例
    @Bean
    @ConditionalOnMissingBean
    public TokenInterceptorRegistry tokenInterceptorRegistry(){
        return new TokenInterceptorRegistry();
    }


    @Bean
    public TokenInterceptor tokenInterceptor(){
        return new TokenInterceptor();
    }



    @Bean
    @ConditionalOnMissingBean
    public TokenUtils tokenUtils(){
        return new TokenUtils();
    }

}
